<meta charset="UTF-8">
<?php
// 获取搜索关键字
require ('./lib/init.php');
$searchWord = $_POST['search'];
if(trim($searchWord) === '') error('检索的关键字不能为空！','javascript:history.back(-1)');
//查询5个栏目
$sql = "select cat_num,cat_name,cat_id from cat order by cat_id limit 5";
$cats = mGetAll($sql);

//查询评论数最高的5篇文章
$sql = "select title,art_id from art order by comm desc limit 5";
$hotarts = mGetAll($sql);

//查询最新四条评论评论
$sql = "select content from comment order by comment_id desc limit 5";
$comments = mGetAll($sql);

//判断地址栏是否有cat_id
if (isset($_GET['cat_id'])){
    $where = " and art.cat_id = $_GET[cat_id]" ;
}else{
    $where = "";
}

//查询所有的文章
$sql = "select art.art_id,author,title,content,pubtime,comm,cat_name,thumb from art inner join cat on 
art.cat_id = cat.cat_id where title like '%$searchWord%' " . $where;
$arts = mGetAll($sql);


// 当前栏目无文章 跳转到首页
if (empty($arts)){
    header('location:artlist.php');
}
require(ROOT . '/view/admin/artlist.html');

